/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xui_lib.component.imageview.crop;

import ohos.agp.window.service.DisplayAttributes;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;

/** 获取dp转换值
 * @since 2021-03-30
 */
public class TypedValue {
    public static final int COMPLEX_UNIT_DIP = 1;

    /** 获取转换值
     * @param unit 转换类型
     * @param value 转换值
     * @param display 屏幕参数
     * @return float
     */
    public static float applyDimension(int unit, float value, DisplayAttributes display) {
        switch (unit) {
            case COMPLEX_UNIT_DIP:
                return value * display.densityPixels;
        }
        return 0;
    }

    /** 获取屏幕数据
     * @param context 上下文
     * @return 实例
     */
    public static DisplayAttributes getDisplayAttributes(Context context) {
        return DisplayManager.getInstance().getDefaultDisplay(context).get().getAttributes();
    }


}
